package com.jinkeen.xiaxie.service

import android.app.Notification
import android.app.NotificationManager
import android.app.Service
import android.content.Intent
import android.os.Build
import android.os.IBinder
import android.os.SystemClock
import android.util.Log
import com.jinkeen.xiaxie.R


class CancelNoticeService : Service() {

    override fun onCreate() {
        super.onCreate()
        Log.e("Adss","ddsafdsfads")
    }

    override fun onBind(intent: Intent): IBinder? =null

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        if (Build.VERSION.SDK_INT>Build.VERSION_CODES.O){
           var build=Notification.Builder(this)
            build.setSmallIcon(R.mipmap.ic_launcher)
            startForeground(110,build.build())
            //开启一条线程 去移除通知
            Thread { // 延迟1s
                SystemClock.sleep(1000)
                // 取消CancelNoticeService的前台
                stopForeground(true)
                // 移除DaemonService弹出的通知
                val manager =
                    getSystemService(NOTIFICATION_SERVICE) as NotificationManager
                manager.cancel(110)
                // 任务完成，终止自己
                stopSelf()
            }.start()
        }
        return super.onStartCommand(intent, flags, startId)
    }

}